package com.test.capsulation;

public class Student {
    String name;
    //1.如何隐藏：使用private关键字修饰成员变量，就能在本类中被直接访问，
    // 但是在其他类中不能被直接访问
    private int age;
    private double chinese;
    private double math;

    //2.如何暴露（合理暴露）：使用public修饰的get和set方法合理暴露
    //成员变量的取值和赋值
    public void setAge(int age) { //为年龄赋值
        if (age > 0 && age < 120) {
            this.age = age;
        } else {
            System.out.println("年龄不合理");
        }
    }
    public int getAge() { //获取年龄
        return age;
    }

    public void setChinese(double chinese) {
        if (chinese >= 0 && chinese <= 100) {
            this.chinese = chinese;
        } else {
            System.out.println("语文成绩不合理");
        }
    }
    public double getChinese() {
        return chinese;
    }

    public void printAllScore() {
        System.out.println(name + "的总分是：" + (chinese + math));
    }

    public void printAverageScore() {
        System.out.println(name + "的平均分是：" + (chinese + math)/2);
    }
}


